package hidalgo.expenses.adapter;

import hidalgo.expenses.entities.Transaction;
import hidalgo.expenses.widgets.TransactionItemView;

import java.util.ArrayList;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

public class TransactionAdapter extends ArrayAdapter<Transaction> {

	private Context context;
	private ArrayList<Transaction> transactionList;

	public TransactionAdapter(Context context, int textViewResourceId,
			ArrayList<Transaction> transactionList) {
		super(context, textViewResourceId);
		this.context = context;
		this.transactionList = transactionList;

	}

	@Override
	public int getCount() {
		return transactionList.size();
	}

	@Override
	public Transaction getItem(int position) {
		return transactionList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return transactionList.get(position).getTransactionId();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		TransactionItemView transactionItemView = new TransactionItemView(
				context);
		transactionItemView.setTransaction(transactionList.get(position));

		return transactionItemView;
	}

}
